package adv41.ano;

import java.lang.reflect.Method;

/**
 * @author oldliu
 * @since 1.0
 */
public class CalcTest {
    public static void main(String[] args) {
        Calc c=new Calc();
//        int add = c.add(10, 40);
//        System.out.println(add);
        //反射的方式调用
        try {
         Method m= c.getClass().getDeclaredMethod("div",int.class,int.class);
         if(m.isAnnotationPresent(MyTest.class)){//方法上是否存在MyTest这个注解
             MyTest myTest=m.getDeclaredAnnotation(MyTest.class);//找到他和他的属性值
             System.out.println(myTest.before());
             Object invoke = m.invoke(c,20, 40);
             System.out.println(m.getName()+"结果是:"+invoke);
             System.out.println(myTest.after());
         }else {
             Object invoke = m.invoke(c,20, 40);
             System.out.println(m.getName()+"结果是:"+invoke);
         }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
